package com.pingan.project.autosendsms;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.renderscript.RenderScript;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by hua on 2016/12/20.
 */

public class TextStaticBroadCast extends BroadcastReceiver {
    Context mC;

    @Override
    public void onReceive(Context context, Intent intent) {
        mC = context;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Log.d("", "TextStaticBroadCast  成功");
                Toast.makeText(mC.getApplicationContext(), "TextStaticBroadCast 成功", Toast.LENGTH_SHORT).show();
                showNotice(mC);
            }
        }, 3000);

    }

    private void showNotice(Context context) {
        NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Sets an ID for the notification, so it can be updated
        int notifyID = 1;
        NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context)
                .setContentTitle("New Message")
                .setContentText("You've received new messages.")
                .setVibrate(new long[] {500L, 200L, 200L, 500L})
                .setSmallIcon(R.mipmap.ic_launcher).setPriority(Notification.PRIORITY_MAX);

        int numMessages = 0;
        mNotifyBuilder.setContentText("66666666")
                .setNumber(++numMessages);
        // Because the ID remains unchanged, the existing notification is
        // updated.
        mNotificationManager.notify(
                notifyID,
                mNotifyBuilder.build());
    }


}
